import request from '@/utils/request'

const api = {
  roles: '/roles',
  getRights: '/rights/tree',
  getMenus: '/menus',
  postRole: '/roles',
  deleteRole: '/roles/',
  detailRole: '/roles/',
  updateRole: '/roles/',
  postRoleRight: '/roles/',
  deelteRightOfRole: '/roles/'
}

export function getRoles() {
  return request({
    url: api.roles,
    method: 'get',
    cache: true
  })
}

export function getRights() {
  return request({
    url: api.getRights,
    method: 'get',
    cache: true
  })
}

export function getMenus() {
  return request({
    url: api.getMenus,
    method: 'get',
    cache: true
  })
}

export function postRole(data) {
  return request({
    url: api.postRole,
    method: 'post',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: `${api.deleteRole}${id}`,
    method: 'delete'
  })
}

export function updateRole(data) {
  return request({
    url: `${api.updateRole}${data.id}`,
    method: 'put',
    data
  })
}

export function detailRole(id) {
  return request({
    url: `${api.detailRole}${id}`,
    method: 'get'
  })
}

export function postRoleRight(data) {
  return request({
    url: `${api.postRoleRight}${data.roleId}/rights`,
    method: 'post',
    data
  })
}

export function deelteRightOfRole(data) {
  return request({
    url: `${api.deelteRightOfRole}${data.roleId}/rights/${data.rightId}`,
    method: 'delete'
  })
}
